
The examples in this (and the next) folder show how a parent
process can control the standard streams (stdin, stdout, stderr)
of a child process.

We would like to be able to do two things with a child's standard
streams, either redirect the streams to files or make the child
"inherit" its parent's standard streams. The details of a child
"inheriting" its parent's standard streams will be discussed in
the next folder.

In Java, when a child process is created, its three standard streams
do not connect to anything! This is unlike Unix (or Windows), where a
child process always inherits its parent's standard streams. In Unix,
if the parent's stdin is the keyboard, then so is the child's stdin.
If the parent's stdout is the console screen, then so is the child's
stdout (and if the parent's stdout is the file foo.txt, then so is
the child's stdout). This is very convenient. In Unix, every child
starts with inheriting its parent's standard streams. Then, if the
parent chooses to, it can also redirect the child's standard streams
to files. The fact that Java does not work this way is a real problem.

(Notice that we are not yet talking about pipes. That is, we do not
yet want to connect the stdout of the parent to the stdin of the child.
That would be a pipe (so would connecting the stdout of the child to
the stdin of the parent). We will discus that in another folder.)

So in Java, we have to do something special just to be able to get
anything into or out of the child process. We will examine the two
cases separately, the case of redirecting the child's standard streams
to files (this folder) and the case of the child inheriting its
parent's standard streams (the next folder).

Using Java 7, we can very elegantly redirect the child's standard
streams to files, but only to files. See the program
   Java7_RedirectChildStdinStdoutToFiles.java.

Using Java 6, we can do the child's I/O redirection, but only in a
very awkward way. The awkward way forces us to simulate the Unix
notion of a "pipe" connecting two streams together. But we have to
create something more like a "pump" in place of a "pipe". Instead of
the output of one stream seamlessly appearing as input to another
stream (if they were connected by a "pipe") we must force (copy)
all the output from one stream to the input of another stream.
See the files
   Java6_RedirectChildStdinStdoutToFiles_ver1.java
   Java6_RedirectChildStdinStdoutToFiles_ver2.java
   Java6_RedirectChildStdinStdoutToFiles_ver3.java.